<div class="fsh-rightPanel">
    <div class="layui-anim layui-anim-upbit">
        <div id="list_form" class="layui-form-item wx-search">
            <div class="layui-inline">
                <label>
                    <input type="text" name="schoolName" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </label>
            </div>
            <button class="layui-btn" id="search">搜索</button>
            <div class="layui-btn-container" style="text-align: right">
                <button class="layui-btn" id="role_add">新增高校</button>
            </div>
        </div>
        <table id="list_table" class="layui-hide" lay-filter="mainList"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="del">删除</button>
    </div>
</script>
<script type="text/html" id="barDemo">
<!--    <a class="font-primary" lay-event="chart">数据统计</a>-->
    <a class="font-primary" lay-event="server">服务器管理</a>
    <a class="font-primary" lay-event="detail">查看</a>
    <a class="font-primary" lay-event="update">编辑</a>
    <a class="font-primary" lay-event="user">成员管理</a>
    <a class="font-primary" lay-event="del">删除</a>
</script>

<script>
    var parentId;
    layui.use(['layer', 'table'], function () {
        var layer = layui.layer;
        var table = layui.table;
        var form = layui.form;

        var tableObj = table.render({
            elem: '#list_table',
            url: context + '/api/school/list',
            //开启头部工具栏，并为其绑定左侧模板，
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {}],
            request: {
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            align: 'center'
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'},
                {field: 'logo', title: 'LOGO', align: 'center', templet: function (d) {
                        return d.logo !== undefined ? '<div><img src="' + d.logo + '" style="height:100px;width:100px;" alt=""/></div>' : '';
                    }
                },
                {field: 'schoolCode', title: '学校编号', align: 'center'},
                {field: 'schoolName', title: '学校名称', align: 'center'},
                {field: 'location', title: '所属城市', align: 'center'},
                // {field: 'level', title: '类别', align: 'center'},
                {field: 'createDate', title: '创建日期', align: 'center'},
                {field: 'handler', title: '操作', align: 'center', width: 400, toolbar: '#barDemo'}
            ]]
            , page: true
        });
        //头工具栏事件
        table.on('toolbar(mainList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    break;
                case 'getCheckLength':
                    break;
                case 'del':
                    confirmDel(context + "'/api/school/' + data[i].id");break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            }
        });

        // 检索
        $("#search").click(function () {
            reloadTable(tableObj);
        });
        // 添加
        $("#role_add").click(function () {
            showDialog({
                title: '新建高校'
                , template: 'add'
                , tableObj: tableObj
                , saveUrl: context + '/api/school/add'
                , type: "post"
                , dataType: 'json'
            })
        });

        //表格内部操作按钮监听
        table.on('tool(mainList)', function (obj) { //注：tool是工具条事件名，mainList是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值

            if (layEvent === 'update') {
                showDialog({
                    title: '编辑高校 - ' + data.schoolName
                    , template: 'add'
                    , saveUrl: context + '/api/school/update'
                    , tableObj: tableObj
                    , htmlData: data
                    , type: "patch"
                    , dataType: 'json'
                })
            }else if (layEvent === 'detail') {
                showDialog({
                    title: '查看高校 - '+ data.schoolName
                    , type: 'get'
                    , template: 'add'
                    , htmlData: data
                })
            }else if (layEvent === 'user') {
                showDialog({
                    title: '成员管理 - ' + data.schoolName
                    , template: 'schoolUser'
                    , htmlData: data
                    , width: '1400'
                    , height: '600'
                })
            }else if (layEvent === 'chart') {
                showDialog({
                    title: '数据统计'
                    , template: 'chart'
                    , tableObj: tableObj
                    , htmlData: data
                    , yes: function (index, layero) {
                        //表单验证
                        layui.form.validate();//默认form名称为add_form（可不填写）
                    }
                })
            }else if (layEvent === 'desc') {
                // showDialog({
                //     title: '高校详情'
                //     , template: 'detail'
                //     , width: 1000
                //     , height: 600
                //     , tableObj: tableObj
                //     , htmlData: data
                //     }
                // })
            }else if (layEvent === 'status') {
                showDialog({
                    title: '更改用户状态'
                    , template: 'status'
                    , tableObj: tableObj
                    , htmlData: data
                })
            }else if (layEvent === 'server') {
                showDialog({
                    title: '服务器 - ' + data.schoolName
                    , template: context + '/views/system/school/schoolServer.html'
                    , tableObj: tableObj
                    , htmlData: data
                    , width: 1000
                    , height: 600
                })
            }else if(layEvent === 'del'){confirmDel(context + "/api/school/del/" + data.school_id , tableObj);}
        });
    });
</script>
<style>
    img.fans-portrait {width: 50px;height: 50px;}
    .fsh-rightPanel .layui-table-body .layui-table-cell {height: 50px;line-height: 50px; }
</style>